import { createPool, Pool } from 'mysql2/promise';
import { config } from '../config';

class Database {
  private static instance: Pool;

  static getInstance(): Pool {
    if (!this.instance) {
      this.instance = createPool({
        host: config.db.host,
        user: config.db.user,
        password: config.db.password,
        database: config.db.database,
        waitForConnections: true,
        connectionLimit: 10,
        queueLimit: 0
      });
    }
    return this.instance;
  }
}

export default Database.getInstance();